<template>
  <ve-modal title="修改实结" v-model="showModal" cancelText="取消" @close="onClose" @confirm="onConfirm">
    <ve-form :noClass="false" :model="form">
      <ve-form-item label="修改为" unit="元" :borderBottom="false">
        <ve-input-number v-model="form.payAmount" :min="0" :max="99999999.99" :precision="2" placeholder="请输入" />
      </ve-form-item>
    </ve-form>
  </ve-modal>
</template>
<script setup lang="ts">
  import { orderFeeModify } from '@/api/order/sOrder'

  import { ref } from 'vue'

  const emit = defineEmits(['getFeeDetail'])

  const showModal = ref(false)
  const form = ref<any>({})
  const openRecord = ref<any>({})
  const open = (price: any) => {
    console.log('open', price)
    openRecord.value = price

    form.value = {
      id: price.id,
      amount: price.amount,
      payAmount: price.payAmount,
    }
    showModal.value = true
  }
  const onClose = () => {
    showModal.value = false
    form.value = {}
  }

  // 点击确认
  const onConfirm = () => {
    // payTypeList -1 嘉联聚合支付
    if ([-1].includes(openRecord.value.payTypeList) && form.value.payAmount < openRecord.value.amount) {
      uni.showToast({
        icon: 'none',
        title: '修改金额需>=聚合支付金额，请重新输入',
      })
      return
    } else if (form.value.payAmount > form.value.amount) {
      uni.showToast({
        icon: 'none',
        title: '修改金额需<=总额，请重新输入',
      })
      return
    }

    orderFeeModify(form.value)
      .then(() => {
        showModal.value = false
        uni.showToast({
          icon: 'none',
          title: '修改成功',
        })
        emit('getFeeDetail')
      })
      .catch(() => {
        showModal.value = false
      })
  }
  defineExpose({
    open,
  })
</script>
<style lang="less" scoped>
  .tips {
    color: #3072f6;
    font-size: 32rpx;
    line-height: 48rpx;
    text-align: center;
  }
  .btn-text {
    font-size: 27rpx;
    color: #3072f6;
  }
  .divider {
    width: 2rpx;
    height: 100%;
    background: #e5e6eb;
  }
  .cancel-text {
    font-size: 27rpx;
    color: #191c27;
  }
</style>
